{% extends 'base.html' %}
{% load score %}

{% block title_suffix %}
    | User {{ viewed_user.username }}
{% endblock %}

{% block content %}
<div class="page-header">
	<h1>{{ viewed_user.first_name }} {{ viewed_user.last_name }}
		<small>{{ viewed_user.username }}</small>
	{% if user.is_staff and not request.session.viewing_as_student %}
		<a class="btn btn-primary pull-right" href="{% url 'auth.views.edit_user' username=viewed_user.username %}">
			<i class="icon-edit icon-white"></i> Edit user
		</a>
	{% endif %}
	</h1>
</div>
<div class="well well-small">
	<table cellpadding="4">
		<tbody>
			<tr>
				<td style="text-align: right;"><strong>Email: </strong></td>
				<td>
				{% if viewed_user.email %}
					<a href="mailto:{{ viewed_user.email }}">{{ viewed_user.email }}</a>
				{% else %}
					-
				{% endif %}
				</td>
			</tr>
			<tr>
				<td style="text-align: right;"><strong>Group(s): </strong></td>
				<td>
				{% if user.is_staff and not request.session.viewing_as_student %}
					{% for group in viewed_user.groups.all %}
						{% url 'auth.views.list_users' as group_url %}
						<a href='{{ group_url }}?group={{ group.name.split|join:"+" }}'>
							{{ group }}
						</a>{% if not forloop.last %},{% endif %}
			    	{% empty %}
					   	-
					{% endfor %}
				{% else %}
					{% for group in viewed_user.groups.all %}
						{{ group }}{% if not forloop.last %},{% endif %}
			    	{% empty %}
					   	-
					{% endfor %}
				{% endif %}
				
				</td>
			</tr>
		</tbody>
	</table>
</div>

<legend>Test Results</legend>
<table class="table table-condensed table-bordered table-striped">
	<thead>
		<th>Test</th>
		<th>Score</th>
		<th># of Correct Answers</th>
		<th>Date & Time</th>
	</thead>
	<tbody>	
	{% for test in test_results %}
		<tr>
			<td>
				{% if test.title %}
				   	{{ test.title }}
				{% else %}
				-
				{% endif %}
			</td>
			<td>
				<div class="progress progress-danger">
					<div class="bar {% score_colour test.score %}" style="width: {{ test.score }}%">{{ test.score }} %</div>
				</div>
			</td>
			<td>
				{% if test.total %}
					{% if test.correct %}
				   		{{ test.correct }} of {{ test.total }}
				   	{% else %}
				   		0 of {{ test.total }}
				   	{% endif %}
				{% else %}
					-
				{% endif %}
			</td>
			<td>
				{% if test.date %}
				   	{{ test.date }}
				{% else %}
					-
				{% endif %}
			</td>
		</tr>
	{% empty %}
		<tr class="info">
			<td colspan="4">No results to display</td>
		</tr>
	{% endfor %}
	</tbody>
</table>
	
{% load pagination %}
{% paginate test_results %}

{% endblock %}

{% block scripts %}
{% endblock %}